package com.example.demo.enums;
//SexEnum.FEMALE.getCode
//SexEnum.FEMALE.getDescription
public enum SexEnum {
    FEMALE(0, "女"),
    MALE(1, "男");

    private final int code;
    private final String description;

    // 构造函数
    SexEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    // 获取枚举对应的代码
    public int getCode() {
        return code;
    }

    // 获取枚举对应的描述
    public String getDescription() {
        return description;
    }

    // 根据代码获取对应的枚举实例
    public static SexEnum getByCode(int code) {
        for (SexEnum sex : values()) {
            if (sex.getCode() == code) {
                return sex;
            }
        }
        throw new IllegalArgumentException("未找到对应的性别代码: " + code);
    }
}